package com.pap.datas.area.controller;

import java.util.List;

import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import com.pap.base.controller.BaseController;
import com.pap.datas.agent.area.IBaseAreaAgent;
import com.pap.datas.agent.area.dto.BaseAreaLeafDTO;
import com.pap.datas.agent.area.dto.BaseAreaTreeNodeVO;
import com.pap.datas.area.auto.entity.BaseArea;

@RestController
@RequestMapping("/v1/data/basearea")
@Api(value="区域操作接口",tags={"区域操作接口"})
public class BaseAreaController extends BaseController<BaseArea, IBaseAreaAgent> {

	@Resource(name = "baseAreaAgent")
	@Override
	public void setService(IBaseAreaAgent service) {
		this.service = service;
	}

	@ApiOperation(value="获取区域树形结构", notes="获取区域树形结构")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "clientLicenseId", value = "授权码标识", required = false, paramType = "header", dataType = "String"),
			@ApiImplicitParam(name = "loginUserId", value = "登录用户标识", required = false, paramType = "header", dataType = "String")
	})
	@RequestMapping(value = "/treejson", method = {RequestMethod.GET})
	public List<BaseAreaTreeNodeVO> treeJSON(@RequestHeader(value = "clientLicenseId", defaultValue = "-1") String clientLicenseId,
			@RequestHeader(value = "loginUserId", defaultValue = "-1") String loginUserId) {
		//  全局默认组织机构的顶层编码为 -1 
		return service.baseAreaTreeJson();
	}

	@ApiOperation(value="根据父级编号获取下一级区域信息", notes="根据父级编号获取下一级区域信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "clientLicenseId", value = "授权码标识", required = false, paramType = "header", dataType = "String"),
			@ApiImplicitParam(name = "loginUserId", value = "登录用户标识", required = false, paramType = "header", dataType = "String"),
			@ApiImplicitParam(name = "parentId", value = "父级区域编号", required = true, paramType = "path", dataType = "String")
	})
	@RequestMapping(value = "/selectchildrenbyid/{parentId}", method = {RequestMethod.GET})
	public List<BaseAreaLeafDTO> selectChildrenById(@RequestHeader(value = "clientLicenseId", defaultValue = "-1") String clientLicenseId,
			@RequestHeader(value = "loginUserId", defaultValue = "-1") String loginUserId,
			@PathVariable String parentId) {
		return service.baseAreaLeafJson(parentId);
	}

}
